package com.wfcm.controller;

import com.wfcm.entity.Distribution;
import com.wfcm.service.DistributionService;
import com.wfcm.utils.ISsoLoginHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: liu
 * @Date: 2018/7/17 15:30
 * @Description: 分销功能
 */
@RestController
@RequestMapping("distribution")
public class DistributionController {

    private static Logger logger = LoggerFactory.getLogger(DistributionController.class);

    @Autowired
    private DistributionService distributionService;

    @RequestMapping("personalCenter")
    public Distribution personalCenter(HttpServletRequest request, @RequestBody Distribution distribution) {
        try {
            distribution.setInviterId(ISsoLoginHelper.confirm(request));
            distributionService.personalCenter(distribution);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            distribution.setErrCode(500);
            distribution.setMsg("exception");
        }
        return distribution;
    }

    @RequestMapping("orderList")
    public Distribution orderList(HttpServletRequest request, @RequestBody Distribution distribution) {
        try {
            distribution.setInviterId(ISsoLoginHelper.confirm(request));
            distributionService.orderList(distribution);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            distribution.setErrCode(500);
            distribution.setMsg("exception");
        }
        return distribution;
    }

    @RequestMapping("userList")
    public Distribution userList(HttpServletRequest request, @RequestBody Distribution distribution) {
        try {
            distribution.setInviterId(ISsoLoginHelper.confirm(request));
            distributionService.userList(distribution);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            distribution.setErrCode(500);
            distribution.setMsg("exception");
        }
        return distribution;
    }
}